//
//  SUNHomeController.swift
//  SUNweibo
//
//  Created by sighting on 16/8/21.
//  Copyright © 2016年 sighting. All rights reserved.
//

import UIKit

private let cellId = "cellId"

class SUNHomeController: SUNBaseViewController {
    
   private lazy var dataList = [String]()
<<<<<<< HEAD
    
//    var isPull = false
    
=======
>>>>>>> parent of 7149882... 添加下拉刷新
 
    // 加载数据
    override func LoadData() {
      
<<<<<<< HEAD
        DispatchQueue.main.after(when: DispatchTime.now() + 1) {
            
            for i in 0..<10 {
                
                // 上拉刷新
                if self.isPull{
                    
                self.dataList.append("上拉\(i)")
                }else{
                // 下拉刷新
                self.dataList.insert(i.description, at: 0)
                }
            }
            
            self.tabView?.reloadData()
            
            self.refresh?.endRefreshing()
            
            self.isPull = false
=======
        for i in 0..<10 {
            dataList.insert(i.description, at: 0)
>>>>>>> parent of 7149882... 添加下拉刷新
        }
        
    }
    
    @objc private func addFriendView(){
        
        let vc = SUNDemoController()
        navigationController?.pushViewController(vc, animated: true)
    }
    
}

// 实现datasource和delegate方法
extension SUNHomeController{

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataList.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tabView?.dequeueReusableCell(withIdentifier: cellId, for: indexPath)
        
        cell?.textLabel?.text = dataList[indexPath.row]
        
        return cell!
    }
<<<<<<< HEAD
    
=======
>>>>>>> parent of 7149882... 添加下拉刷新
}

// MARK:设置界面
extension SUNHomeController{
    
    override func setUI() {
        super.setUI()
        
        // MARK:navigationItem左侧按钮设置
        navItem.leftBarButtonItem = UIBarButtonItem(title: "好友", target: self, action: #selector(addFriendView))
        
        // 注册cell
        tabView?.register(UITableViewCell.self, forCellReuseIdentifier: cellId)
    }
    
}

